#include<bits/stdc++.h>
using namespace std;
class BaseAccount
{
    protected:
        string name,account;
        int balance;
    public:
        BaseAccount(string na,string ac,int ba)
        {
            name=na;
            account=ac;
            balance=ba;
        }
        void deposit(int m)
        {
            balance+=m;
        }
        virtual void withdraw(int m)
        {
            if(m>balance)
                cout<<"insufficient\n";
            else
            {
                balance-=m;
            }
        }
        virtual void display()
        {
            cout<<name<<" "<<account<<" Balance:"<<balance<<"\n";
        }
};
class BasePlus:public BaseAccount
{
    protected:
        int limit,limitSum;
    public:
    BasePlus(string na,string ac,int ba,int li=5000,int liS=0):BaseAccount(na,ac,ba)
    {
        limit=li;
        limitSum=liS;
    }
    virtual void withdraw(int m)
    {
        if(m>(limit+balance))
        {
            cout<<"insufficient\n";
            return;
        }
        if(m>=balance)
        {
            limitSum+=(m-balance);
            limit-=(m-balance);
            balance=0;
        }
        else
        {
            balance-=m;
        }
    }
    virtual void display()
    {
        cout<<name<<" "<<account<<" Balance:"<<balance<<" limit:"<<limit<<"\n";
    }
};
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        BaseAccount* pv;
        string name,ac;
        int bala;
        cin>>name>>ac>>bala;
        if(ac[1]=='A')
        {
            pv=new BaseAccount(name,ac,bala);
            int flag=1;
            int cnt=4;
            while(cnt--)
            {
                int num;
                cin>>num;
                if(flag==1)
                {
                    pv->deposit(num);
                    flag=0;
                }
                else
                {
                    pv->withdraw(num);
                    flag=1;
                }
            }
            pv->display();
        }
        else if(ac[1]=='P')
        {
            pv=new BasePlus(name,ac,bala);
            int flag=1;
            int cnt=4;
            while(cnt--)
            {
                int num;
                cin>>num;
                if(flag==1)
                {
                    pv->deposit(num);
                    flag=0;
                }
                else
                {
                    pv->withdraw(num);
                    flag=1;
                }
            }
            pv->display();
        }
    }
}